package utils;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * 调用Runtime.getRuntime().exec后，如果不及时捕捉进程的输出，会导致JAVA挂住
 * 启动进程后，再启动两个JAVA线程及时的把被调用进程的输出截获
 * 
 * @author HZJ
 *
 */
public class StreamGobbler extends Thread {

	BufferedReader bReader = null;
	String type = null;

	public StreamGobbler(InputStream is, String _type) {
		try {
			bReader = new BufferedReader(new InputStreamReader(new BufferedInputStream(is), "UTF-8"));
			type = _type;
		} catch (Exception ex) {
		}
	}

	public void run() {
		String line;
		int lineNum = 0;

		try {
			while ((line = bReader.readLine()) != null) {
				lineNum++;
				// Thread.sleep(200);
			}
			bReader.close();
		} catch (Exception ex) {
		}
	}
}

